// 根据数组计算
import { isQueue, _mid, _dis, _atan, _polar, _k } from './index.js'

// 镜像
// Angle of Refraction折射角
// index of Refraction折射角
export const _mirror = (p, o, scale = 1, refraction) => {
  if (isQueue(p)) {
    let n = p.length
    return p.map((t, i) => _mirror(t, o, scale, refraction))
  }
  if (refraction) {
    let r = _dis(p, o) * scale
    let a = _atan(p, o)
    let ra = a + refraction
    return _polar(o, r, ra)
  }
  if (scale === 1) {
    return [2 * o[0] - p[0], 2 * o[1] - p[1]].map(t => _k(t))
  }
  return [(scale + 1) * o[0] - scale * p[0], (scale + 1) * o[1] - scale * p[1]].map(t => _k(t))
}
// 边镜像
export const edgeMirror = (points, options) => {
  let {
    ratio = 1,
    refraction,
  } = options
  let midPoints = _mid(points)
  return midPoints.map((t) => {
    return _mirror(points, t, ratio, refraction)
  })
}